home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / toolbox / show_prop < prev    next >
Text File  |  1994-09-23  |  3KB  |  106 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. // Synopsis:    print and plot section info
  4.  
  5. // Syntax:    show_prop ( P , s, coord )
  6.  
  7. // Description:
  8.  
  9. //    The properties of polygonal sections may be calculated using rfile
  10. //  section.  These section properties can be shown on the screen by 
  11. //  this rfile.    
  12. //  
  13. //  The (x,y) coordinates of the vertices of the polygon are stored 
  14. //  in P.  P is a two column matrix,  its first column stores xs and
  15. //  its second column stores ys.   The coordinates of the vertces must
  16. //  be stored sequentially for a complete clockwise path around the 
  17. //  polygon.
  18.  
  19. //  s stores section properties (returned from section.r)
  20.  
  21. //  If coord is "polar", then the coordinates in P are in polar 
  22. //  coordinates (r,theta), where theta is in degree.
  23. //
  24. // Dependencies
  25. //   rfile plplot.r
  26. //
  27. //  Tzong-Shuoh Yang  8/10/94   (tsyang@ce.berkeley.edu)
  28. //-------------------------------------------------------------------//
  29.  
  30. show_prop = function(P,s,coord)
  31. {
  32.    local(P,mx,mn,pp,x,y,xp,yp,R,t,T,ps)
  33.    global (pi)
  34.  
  35.    // if the polygon is not closed, let the last point = 1st point
  36.    if (P[P.nr;1] != P[1;1] || P[P.nr;2] != P[1;2] )
  37.    {
  38.        P = [P;P[1;1],P[1;2]];
  39.    }
  40.    // convert polar coordinates to cartesian coordinates
  41.    if (exist(coord)) 
  42.    {  if (coord == "polar")
  43.       {
  44.          P[;2] = P[;2]*(pi/180);
  45.          P = [P[;1].*cos(P[;2]),P[;1].*sin(P[;2])];
  46.       }
  47.    }
  48.    
  49.    if (s.area < 0) 
  50.    {
  51.      printf(" Area = %g (hole ?)\n\n",s.area);
  52.    else
  53.      printf(" Area = %g\n\n",s.area);
  54.    }
  55.    printf(" Centroid = (%g,%g)\n\n",s.cgx,s.cgy);
  56.    printf(" Moment of Inertia: (Original axis)\n");
  57.    printf("                    Ixx = %g\n",s.Ixx);
  58.    printf("                    Iyy = %g\n",s.Iyy);
  59.    printf("                    Ixy = %g\n\n",s.Ixy);
  60.    printf(" Moment of Inertia: (Centroid axis)\n");
  61.    printf("                    Ixx = %g\n",s.Ixx0);
  62.    printf("                    Iyy = %g\n",s.Iyy0);
  63.    printf("                    Ixy = %g\n\n",s.Ixy0);
  64.    printf(" Moment of Inertia: (Principal axis)\n");
  65.    printf("                    Ixx = %g\n",s.pIxx);
  66.    printf("                    Iyy = %g\n",s.pIyy);
  67.    printf("                  angle = %g (deg)\n\n",s.angle);
  68.    printf(" Polar Moment of Inertia:\n");
  69.    printf("                      J = %g\n\n",s.J0);
  70.    sprintf(ps,"Properties: A=%.3g I#+XX#+=%.3g I#+YY#+=%.3g I#+XY#+=%.3g",...
  71.            s.area,s.Ixx0,s.Iyy0,s.Ixy0);
  72.    
  73.    mx = max(P);
  74.    mn = min(P);
  75.    pp = abs(mx-mn)*0.2;
  76.    plimits(mn[1;1]-pp[1;1],mx[1;1]+pp[1;1],mn[1;2]-pp[1;2],mx[1;2]+pp[1;2]);
  77.    // plaspect(1);
  78.    // plgrid("abcnst","abcnst");
  79.    ptitle(ps);
  80.    xlabel("X");
  81.    ylabel("Y");
  82.    plegend();
  83.    x = [mx[1;1]+pp[1;1]/2,s.cgy;mn[1;1]-pp[1;1]/2,s.cgy];
  84.    y = [s.cgx,mx[1;2]+pp[1;2]/2;s.cgx,mn[1;2]-pp[1;2]/2];
  85.    t = s.angle*pi/180;
  86.    R = [cos(t),sin(t);-sin(t),cos(t)];
  87.    T = [s.cgx,s.cgy;s.cgx,s.cgy];
  88.    xp = (x-T)*R+T;
  89.    yp = (y-T)*R+T;
  90.    if (abs(s.angle) > 0.001) {
  91.       plot(<<P;x;y;xp;yp>>);   
  92.    else
  93.       plot(<<P;x;y>>);
  94.    }
  95.    sprintf(ps," CG(%.3g,%.3g)",s.cgx,s.cgy);
  96.    plptex(ps,s.cgx,s.cgy+pp[1;2]/5,1,0,0);
  97.    plptex(" #+Y",s.cgx,mx[1;2]+pp[1;2]/2,1,0,0);
  98.    plptex(" #+X",mx[1;1]+pp[1;1]/2,s.cgy,1,0,0); 
  99.    if (abs(s.angle) > 0.001) {
  100.       plptex(" #+Y#+'",yp[1;1],yp[1;2],1,0,0);
  101.       plptex(" #+X#+'",xp[1;1],xp[1;2],1,0,0); 
  102.       sprintf(ps," #gh=%.3g#uo",s.angle);
  103.       plptex(ps,s.cgx,s.cgy+pp[1;2],1,0,0);   
  104.    }
  105. };
  106.